﻿using System;
using System.Diagnostics;

namespace SfsTools.Core
{
    /// <summary>
    /// Represents a pair of <see cref="BlockRegion"/>s
    /// </summary>
    [DebuggerDisplay("Free: {A} Used: {B}")]
    internal struct BlockRegionPair : ICloneable
    {
        #region Properties

        /// <summary>
        /// Contains the first <see cref="BlockRegion"/>.
        /// </summary>
        private BlockRegion FA;
        /// <summary>
        /// Gets or sets the first <see cref="BlockRegion"/>.
        /// </summary>
        public BlockRegion A
        {
            [DebuggerStepThrough]
            get
            {
                return FA;
            }
            [DebuggerStepThrough]
            set
            {
                FA = value;
            }
        }

        /// <summary>
        /// Contains the second <see cref="BlockRegion"/>.
        /// </summary>
        private BlockRegion FB;
        /// <summary>
        /// Gets or sets the second <see cref="BlockRegion"/>.
        /// </summary>
        public BlockRegion B
        {
            [DebuggerStepThrough]
            get
            {
                return FB;
            }
            [DebuggerStepThrough]
            set
            {
                FB = value;
            }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Returns a <see cref="String"/> that represents the current <see cref="BlockRegionPair"/>.
        /// </summary>
        /// <returns>A <see cref="String"/> that represents the current <see cref="BlockRegionPair"/>.</returns>
        [DebuggerStepThrough]
        public override string ToString()
        {
            return new System.Text.StringBuilder().
                Append('[').Append(FA.ToString()).Append(',').Append(FB.ToString()).Append(']').
                ToString();
        }

        #endregion

        #region Constructors
        /// <overloads>Initializes a new instance of <see cref="BlockRegionPair"/>.</overloads>
        /// <summary>
        /// Initializes a new instance of <see cref="BlockRegionPair"/>.
        /// </summary>
        /// <param name="a">The first <see cref="BlockRegion"/>.</param>
        /// <param name="b">The second <see cref="BlockRegion"/>.</param>
        [DebuggerStepThrough]
        public BlockRegionPair(BlockRegion a, BlockRegion b)
        {
            FA = a;
            FB = b;
        }
        /// <summary>
        /// Initializes a new instance of <see cref="BlockRegionPair"/> from an existing instace.
        /// </summary>
        /// <param name="value">The instance to copy.</param>
        [DebuggerStepThrough]
        public BlockRegionPair(BlockRegionPair value)
        {
            // ReSharper disable RedundantThisQualifier
            this.FA = value.FA;
            this.FB = value.FB;
            // ReSharper restore RedundantThisQualifier
        }
        #endregion
                
        #region ICloneable Members
        
        /// <summary>
        /// Creates a new <see cref="BlockRegionPair"/> that is the copy of the current instance.
        /// </summary>
        /// <returns>A new <see cref="BlockRegionPair"/> that is the copy of the current instance.</returns>
        [DebuggerStepThrough]
        public BlockRegionPair Clone()
        {
            return new BlockRegionPair(this);
        }
        
        /// <summary>
        /// Creates a new <see cref="BlockRegionPair"/> that is the copy of the current instance.
        /// </summary>
        /// <returns>A new <see cref="BlockRegionPair"/> that is the copy of the current instance.</returns>
        [DebuggerStepThrough]
        object ICloneable.Clone()
        {
            return new BlockRegionPair(this);
        }
        
        #endregion
    }
}
